package com.fuxi;

import java.util.*;

/**
 * @ClassName: day1
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2025/3/30-21:44
 * @Version 1.0
 */
public class Day1 {
    public static void main(String[] args) {
        // 数据转化，
        //1 小数据自动转化为大数据
//        byte a = 10;
//        int b = a;
//        System.out.println(b);
//        // 转化前后数据类型要兼容
//        // 整型类型和浮点类型继续计算，结果会转化为浮点类型
//        int f = 1;
//        byte f1 = (byte) f;
//        System.out.println(f1);
//        Collection_demo();
        User a = new User("aa" ,13);
        User b = new User("bb", 14);
        User c = new User("cc", 14);
        List<User> list = new ArrayList<User>();
        list.add(a);
        list.add(b);
        list.add(c);
        Collections.sort(list, new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                int age =  o1.age - o2.age;
                return  age == 0 ? o1.getName().compareTo(o2.getName()) : age;
            }
        });
        list.forEach(System.out::println);
    }


    public static void Collection_demo() {
        List<Object> list = new ArrayList<Object>();
        list.add("123");
        list.add(1);
        for (Object o : list) {
            System.out.println(o);
        }
        Iterator<Object> iterator = list.iterator();
        while (iterator.hasNext()){
            Object next = iterator.next();
            System.out.println(next);
        }
    }
    static class User {
        private String name;
        private int age;
        public User(String name, int age) {
            this.age = age;
            this.name = name;
        }
        @Override
        public String toString() {
            return "user{" + "age =" + age + "name=" + name+ '\''+ "}";
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
